package com.four.reimbursemanage.service.impl;

import com.four.reimbursemanage.common.bean.Page;
import com.four.reimbursemanage.dao.EntertainApplyDao;
import com.four.reimbursemanage.entity.EntertainApply;
import com.four.reimbursemanage.entity.Payapply;
import com.four.reimbursemanage.service.EntertainApplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class EntertainApplyServiceImpl implements EntertainApplyService {
    @Autowired
    private EntertainApplyDao entertainApplyDao;
    @Override
    public Page<EntertainApply> getOnrePage(int pageNum, int pageSize, Date month, Integer is_settlement) {
        //计算起始位置
        int start=(pageNum-1)*pageSize;
        //获取分页的数据
        List<EntertainApply> list=entertainApplyDao.selectEntertainApplyList(start, pageSize, month, is_settlement);
        //获取总条目数
        int total=entertainApplyDao.countEntertainApply(month, is_settlement);
        //计算总页数
        int pages =(int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
        //创建分页对象
        Page<EntertainApply> page=new Page<>();
        page.setRecords(list);
        page.setTotal(total);
        page.setPages(pages);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        return page;
    }

    /*结算*/
    @Override
    public boolean updateSuccess(EntertainApply entertainApply) {
        if (entertainApply==null){
            return false;
        }
        entertainApply.setIs_settlement(1);
        return entertainApplyDao.updateSettlement(entertainApply)>0;
    }
}
